<template>
  <div>
    <el-container>
      <el-header>
        <el-row id="top">
          <el-col :span="3">
            <div id="top-1">&nbsp</div>
          </el-col>
          <el-col :span="4">
            <div id="top-2"> &nbsp臻&nbsp</div>
          </el-col>
          <el-col :span="10">&nbsp</el-col>
          <el-col :span="6">
            <div id="top-3"><i class="el-icon-s-home"></i>身体、灵魂的释放生活</div>
            <div>800-820-8820</div>
          </el-col>
        </el-row>
      </el-header>

      <el-main>
        <el-row id="no1">
          <el-col :span="4" id="centre-left">&nbsp</el-col>
          <el-col :span="16" id="centre">
            <div id="form">
              <el-form v-if="!showCodeLogin" ref="loginForm" :model="loginForm">
                <el-form-item>
                  <el-link type="success" @click="switchToUsernameLogin">账号登录</el-link>
                  &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                  <el-link type="primary" @click="switchToCodeLogin">快捷登录</el-link>
                </el-form-item>
                <el-form-item label="账号:" prop="coachName">
                  <el-input v-model="loginForm.coachName" placeholder="请输入账号" style="width: 240px;"></el-input>
                </el-form-item>
                <el-form-item label="密码:" prop="coachPassword">
                  <el-input type="password" v-model="loginForm.coachPassword" placeholder="请输入密码"
                    style="width: 240px;"></el-input>
                </el-form-item>
                <el-form-item>
                  <span color="">想成为教练？--></span>
                  &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                  <el-button type="text" @click="goToRegister">免费注册</el-button>
                </el-form-item>
                <el-form-item>
                  <el-button type="danger" @click="usernameLogin" style="width: 300px;">立即登录</el-button>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="VenueLogin">场馆登录</el-button>
                  <el-button type="primary" @click="AdminLogin">管理员登录</el-button>
                </el-form-item>
              </el-form>

              <el-form v-else ref="codeLoginForm" :model="codeLoginForm" label-width="80px" style="max-width: 400px; margin: auto;">
                <el-form-item label="手机号" prop="userPhone">
                  <el-input v-model="codeLoginForm.coachPhone"></el-input>
                </el-form-item>
                <el-form-item label="验证码" prop="code">
                  <el-input v-model="codeLoginForm.code"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="sendCode">发送验证码</el-button>
                  <el-button type="primary" @click="codeLogin">登录</el-button>
                  <el-button type="text" @click="switchToUsernameLogin">使用用户名密码登录</el-button>
                </el-form-item>
              </el-form>
            </div>
          </el-col>
          <el-col :span="4" id="centre-right">&nbsp &nbsp</el-col>
        </el-row>
      </el-main>

      <el-footer id="end">
        Copyright © 2024-3024 重庆LadyYoGo有限责任公司 版权所有
      </el-footer>
    </el-container>
  </div>
</template>
<script>
  export default {
    name:"CoachLogin",
    data() {
      return {
        loginForm: {
          coachName: '',
          coachPassword: ''
        },
        codeLoginForm: {
          coachPhone: '',
          code: ''
        },
        sendingCode: false,
        loggingIn: false,
        showCodeLogin: false
      }
    },
    methods: {
      VenueLogin() {
        this.$router.push('/VenueLogin');
      },
      AdminLogin() {
        this.$router.push('/AdminLogin');
      },
      goToRegister() {
        this.$router.push('/coachRegister');
      },
      //发送验证码
      sendCode() {
        this.sendingCode = true;
        this.$http.get('/account/yCoach/LoginCodePhone', {
            params: {
              mobile: this.codeLoginForm.coachPhone
            }
          })
          .then(resp => {
            this.$message.success(resp.data.msg);
          });
      },
      //验证码登录
      codeLogin() {
        this.loggingIn = true;
        this.$http.post('/account/yCoach/phoneLogin', {
            coachPhone: this.codeLoginForm.coachPhone,
            code: this.codeLoginForm.code
          })
          .then(response => {
            // 登录成功处理逻辑
            this.$router.push("/CoachManagement");
            this.$message.success(response.data.msg);
          });
      },
      //教练账号和密码登录
      usernameLogin() {
        this.loggingIn = true;
        this.$http.post('/account/yCoach/coachLogin', {
            coachName: this.loginForm.coachName,
            coachPassword: this.loginForm.coachPassword
          })
          .then(resp => {
            if (resp.data.code==200) {
              this.$message.success(resp.data.msg);
              //登录成功跳转教练个人中心
              this.$router.push("/CoachHome");
            } else {
              alert(resp.data.msg)
              this.loggingIn = false
            }

          })

      },
      switchToCodeLogin() {
        this.showCodeLogin = true;
      },
      switchToUsernameLogin() {
        this.showCodeLogin = false;
      }
    },
    created() {

    }
  }
</script>

<style>
  #top-3 {
    font-family: '华文新魏';
    margin-top: 30px;
    font-size: 25px;
  }

  #top-2 {
    font-family: '华文彩云';
    margin-top: 30px;
    font-size: 25px;
  }

  #top-1 {
    margin-left: 70px;
    line-height: 80px;
    background-image: url(/static/logo.png);
    background-size: contain;
  }

  * {
    margin: 0;
    padding: 0;
  }


  #no1 {
    line-height: 290px !important;
    margin-top: 15px;
    background-image: url(/static/jiaolian.jpg);
    background-size: cover;
    background-position: center -200px;

  }

  #centre-right {
    height: 450px;
  }

  #centre-left {
    height: 450px;
  }

  #centre-1 {
    height: 500px;
  }

  #form {
    font-size: 20px;
    font-family: '华文行楷';
    margin-left: 750px;
    height: 400px;
    width: 350px;
    text-align: center;
    background-color: white;
    border: 1px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  #centre {
    background-size: cover;
    margin-block-start: 6%;
    height: 430px;
  }

  #top {
    text-align: center;
    line-height: 30px;
  }

  #end {
    text-align: center;
    line-height: 30px;
  }
</style>
